package main.java.indi.zyj.c150.dps;

import java.util.Scanner;

public class _08_PerfectWork {


    static int n, ans;
    static int[][] task = new int[15][15];
    static boolean[] visited = new boolean[15];


    static void Dfs(int number, int t){
        if (number == n){
            if (t < ans){
                ans = t;
            }
            return;
        }
        for (int i = 0; i < n; i++) {
            if (!visited[i]){
                visited[i] = true;
                Dfs(number+1, t + task[number][i]);
                visited[i] = false;
            }
        }
    }


    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);

        System.out.println("请输入员工人数：");
        n = scan.nextInt();

        System.out.println("请输入员工完成对应任务行列式：");
        for (int i = 0; i < n; i++) {
            String s = scan.next();
            for (int j = 0; j < n; j++) {
                task[i][j] = s.charAt(j);
            }
        }

        ans = 100000;
        Dfs(0, 0);
        System.out.println("最少工作量为：" + ans);
    }

}
